<!--
 * @Author: your name
 * @Date: 2020-10-24 19:06:55
 * @LastEditTime: 2020-10-24 22:05:34
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \mall-admin\src\views\system\dict\module\form.vue
-->
<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" :title="isAdd?'新增数据字典':'修改数据字典'" width="600px">
  <el-form ref="form" :model="form"  size="small" label-width="120px">
      <el-form-item label="字典代码：" prop="dictNo">
        <el-input v-model="form.dictNo" style="width: 360px;"/>
      </el-form-item>
    </el-form>
    <el-form ref="form" :model="form"  size="small" label-width="120px">
      <el-form-item label="名称：" prop="dictName">
        <el-input v-model="form.dictName" style="width: 360px;"/>
      </el-form-item>
    </el-form>
     <el-form ref="form" :model="form"  size="small" label-width="120px">
      <el-form-item label="值:" prop="dictVal">
        <el-input v-model="form.dictVal" style="width: 360px;"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
export default {
  props: {
    isAdd: {
      type: Boolean,
      required: true
    },
    sup_this: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      loading: false,
      dialog: false,
      form: { dictName: "",pdictNo:'', id:'',dictStatus:'1'},
      // {
      //   "dictDesc": "string",
      //   "dictName": "string",
      //   "pdictNo": "string"
      //   "dictVal": "string",
      //   "dictStatus": "1",
      //   "dictNo": "string",
      //   "id": "string",
      // }
      dateValue: "",
      rules: {
        dictName: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ]
      },
      authData:{},
      dictNo:''
    }
  },
  mounted(){
    console.log(this.dialog)
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      if(this.isAdd){
        this.add()
      }else{
        this.edit()
      }
    },
    add(){
       const obj = Object.assign({}, this.form, { dictDesc: this.form.dictName,dictNo:this.form.dictNo,dictVal:this.form.dictVal})
       this.$api.fenxiao.sysDict.insert({
         data: obj
       }).then(res => {
         this.resetForm()
         this.$notify({
           title: '新增成功',
           type: 'success',
           duration: 2500
         })
        this.loading = false
        this.$parent.findByPdictCode(this.dictNo)
       }).catch(err => {
         this.loading = false
         console.log(err.response)
       })
    },
    edit(){
      const obj = Object.assign({}, this.form, { dictDesc: this.form.dictName,dictNo:this.form.dictNo,dictVal:this.form.dictVal})
       this.$api.fenxiao.sysDict.update({
         data: obj
       }).then(res => {
         this.resetForm()
         this.$notify({
           title: '修改成功',
           type: 'success',
           duration: 2500
         })
        this.loading = false
        this.$parent.getLists(this.dictNo)
       }).catch(err => {
         this.loading = false
         console.log(err.response)
       })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = { dictName: "",dictNo:'',id:'',dictStatus:'1'}
    }
  }
}
</script>

<style scoped>

</style>
